﻿/*
===========================================================================

  Copyright (c) 2010-2014 Darkstar Dev Teams

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see http://www.gnu.org/licenses/

  This file is part of DarkStar-server source code.

===========================================================================
*/

#ifndef _MMO_H
#define _MMO_H

#include "cbasetypes.h"

#include <string>
#include <time.h>

#define FIFOSIZE_SERVERLINK	256*1024

#define FFXI_HEADER_SIZE 0x1C		// Common packet header size
#define FFXI_CHANGE_ZONE 0x0A		// Change zone cmd

// флаги перед именем персонажа
// Flags in front of the name of the character

enum FLAGTYPE
{
    FLAG_INEVENT        = 0x00000002,
    FLAG_CHOCOBO        = 0x00000040,
    FLAG_WALLHACK       = 0x00000200,
    FLAG_INVITE         = 0x00000800,
    FLAG_ANON           = 0x00001000,
    FLAG_UNKNOWN        = 0x00002000,
    FLAG_AWAY           = 0x00004000,
    FLAG_PLAYONLINE     = 0x00010000,
    FLAG_LINKSHELL      = 0x00020000,
    FLAG_DC             = 0x00040000,
    FLAG_GM             = 0x04000000,
    FLAG_GM_SUPPORT     = 0x04000000,
    FLAG_GM_SENIOR      = 0x05000000, // FLAG_GM+0x01000000
    FLAG_GM_LEAD        = 0x06000000, // FLAG_GM+0x02000000
    FLAG_GM_PRODUCER    = 0x07000000, // FLAG_GM+0x03000000
    FLAG_BAZAAR         = 0x80000000,

//  FLAG_AUTOGROUP      = 0x00000000,
//  FLAG_NEWPLAYER      = 0x00000000,
//  FLAG_MENTOR         = 0x00000000,

// Run out of bits here = 0xFFFFFFFF
};

enum ELEMENTS
{
    FIRE		= 0x01,
    ICE			= 0x02,
    WIND		= 0x04,
    EARTH		= 0x08,
    THUNDER		= 0x10,
    WATER		= 0x20,
	LIGHT		= 0x40,
	DARK		= 0x80,
};

typedef std::string string_t;

// для персонажей в size хранится рост,
// для npc и монстров что-то вроде типа используемой модели
// Size of the characters in the store growth
// Npc and monsters for a bit of product model

struct look_t
{
	uint16 size;
	uint8  face, race;
	uint16 head, body, hands, legs, feet, main, sub, ranged;
};

struct skills_t
{
	union {
		struct {
			// SkillID 0
			uint16 unknown1;
			// SkillID  1-12
			uint16 h2h, dagger, sword, gsword, axe, gaxe, scythe, polearm, katana, gkatana, club, staff;
			// SkillID 13-21
			uint16 reserved1[9];
            // SkillID 22-24
            uint16 automaton_melee, automaton_ranged, automaton_magic;
			// SkillID 25-33
			uint16 archery, marksmanship, throwing, guarding, evasion, shield, parrying, divine, healing;
			// SkillID 34-43
			uint16 enhancing, enfeebling, elemental, dark, summoning, ninjutsu, singing, string, wind, blue;
			// SkillID 44-47
			uint16 reserved2[4];
			// SkillID 48-54
			uint16 fishing, woodworking, smithing, goldsmithing, clothcraft, leathercraft, bonecraft;
			// SkillID 55-58
			uint16 alchemy, cooking, synergy, riding;
			// SkillID 59-62
			uint16 reserved3[4];
			// SkillID 63
			uint16 unknown2;
		};
		// index SkillID 0-63
		uint16 skill[64];
	};
	// ранг используется только в ремеслах. размер 64 необходим для совместимости ID
	// Rank is used only in the arts. size of 64 is required for compatibility ID
	uint8 rank[64];
};

struct keyitems_t
{
	 uint8 keysList[320];	// таблица ключевых предметов Table of key items
	 uint8 seenList[320];	// таблица ключевых предметов, отмеченных как "увиденные" Table of key items that are marked as "seen"
};

struct position_t
{
	uint8 rotation;			// угол поворота сущности относительно своей позиции (используется 255 система, место 360°)
                            // Angle of rotation of the essence with respect to its position (using 255 systems, the 360 °)
	float x;				//
	float y;				// высота расположения сущности относительно "уровня моря"
							// Height the location of essence relatively "sea level"
	float z;                //
	uint16 moving;			// что-то вроде расстояния перемещения, необходимое для правильной отрисовки в клиенте количества шагов сущности
                            // Sort of distance traveled, necessary for the proper rendering of the number of steps in the client entity
};

struct stats_t
{
	uint16 STR,DEX,VIT,AGI,INT,MND,CHR;
};

struct questlog_t
{
	uint8 current [32];
	uint8 complete[32];
};

struct missionlog_t
{
	uint16 current;
	bool   complete[64];
};

struct assaultlog_t
{
	uint16 current;
	bool   complete[128];
};

struct campaignlog_t
{
	uint16 current;
	bool   complete[512];
};

struct nameflags_t
{
	union {
		struct {
			uint8 byte1;
			uint8 byte2;
			uint8 byte3;
			uint8 byte4;
		};
		uint32 flags;
	};
};

// информация для окна поиска
// Information for the search box
struct search_t
{
	uint8 language;			// предпочтительный язык общения The preferred language of communication
	uint8 messagetype;		// тип комментария Type of comment

	string_t message;		// комментарий поиска Comment search
};

struct bazaar_t
{
	string_t message;
};

// небольшой комментарий к пакетам ниже, определенным в виде констант
// 1-й байт - размер пакета
// через 4-ре байта начинается заголовк 0x49, 0x58, 0x46, 0x46 - IXFF
// после заголовка идет предположительно тип сообщения:
// 0x03 - положительный результат
// 0x04 - ошибка (в случае ошибки начиная с 33 байта идет код ошибки uint16)
// A comment on the packages below, defined as constants
// 1 byte - packet size
// A 4-D bytes File Title starts 0x49, 0x58, 0x46, 0x46 - IXFF
// After the title is presumably the type of message:
// 0x03 - positive
// 0x04 - error (in the case of error ranging from 33 bytes is an error code uint16)

#define LOBBY_A1_RESERVEPACKET(a)\
unsigned char a[] = { \
		0xc4, 0x01, 0x00, 0x00, 0x49, 0x58, 0x46, 0x46, 0x20, 0x00, 0x00, 0x00, 0x2a, 0x72, 0x4a, 0x94, \
		0x4f, 0x60, 0x27, 0xc4, 0x45, 0x4b, 0x7d, 0xcf, 0x27, 0x8e, 0x6d, 0xcd, 0x03, 0x00, 0x00, 0x00, \
		0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, \
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x61, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, \
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x05, 0x00, \
		0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x02, 0x00, 0x10, 0x00, 0x20, 0x00, 0x30, \
		0x00, 0x40, 0x00, 0x50, 0x00, 0x60, 0x00, 0x70, 0x00, 0x01, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, \
		0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0xfa, 0x01, 0x00, \
		0x7e, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, \
		0x01, 0x01, 0x01, 0x01, 0x46, 0x6e, 0xcf, 0x09, 0xde, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
		0x0a, 0x52, 0x03, 0x00, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00							\
}

#define LOBBY_A2_RESERVEPACKET(a)\
unsigned char a[]={ \
		0x48, 0x00, 0x00, 0x00, 0x49, 0x58, 0x46, 0x46, 0x0b, 0x00, 0x00, 0x00, 0x30, 0xD0, 0x10, 0xDC,\
		0x87, 0x64, 0x4B, 0x34, 0x72, 0x9A, 0x51, 0x23, 0x54, 0x14, 0x67, 0xF0, 0x82, 0xB2, 0xc0, 0x00,\
		0xC3, 0x57, 0x00, 0x00, 0x52, 0x65, 0x67, 0x69, 0x75, 0x7A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
		0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x01, 0xd6, 0xd3, 0x00, 0x00,\
		0x7F, 0x00, 0x00, 0x01, 0xf2, 0xd2, 0x00, 0x00\
	}

#define LOBBY_026_RESERVEPACKET(a) \
unsigned char a[]={\
		0x28, 0x00, 0x00, 0x00, 0x49, 0x58, 0x46, 0x46, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0xe0, 0x5d, 0xad,\
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\
	}

#define LOBBY_024_RESERVEPACKET(a) \
unsigned char a[]={ \
		0x40, 0x00, 0x00, 0x00, 0x49, 0x58, 0x46, 0x46, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,\
		0x64, 0x00, 0x00, 0x00, 0x70, 0x58, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \
	}

#define LOBBY_ACTION_DONE(a)\
unsigned char a[]={\
			0x20, 0x00, 0x00, 0x00, 0x49, 0x58, 0x46, 0x46, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\
		}

#define LOBBBY_ERROR_MESSAGE(a)\
unsigned char a[]={ \
			0x24, 0x00, 0x00, 0x00, 0x49, 0x58, 0x46, 0x46, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
			0x00, 0x00, 0x00, 0x00\
		}

#define LAN_CONFIG_NAME "conf/lan_config.conf"

struct lan_config_t
{
	uint32 uiLoginLanIP;
	uint16 usLoginLanPort;

	uint32 uiMapLanIP;
	uint16 usMapLanPort;

	uint32 wait_time;
	uint8  connect_try_num;
};


class char_mini
{
public:

	int8	m_name[16];

	uint8	m_mjob;
	uint16	m_zone;
	uint8	m_nation;

	look_t	m_look;

	 char_mini() {};
	~char_mini() {};
};

#endif // _MMO_H